package stack;

import java.util.Map;
import java.util.Stack;

public class p20 {
    public static void main(String[] args) {
        Solution solution=new Solution();
        System.out.println(solution.isValid("([])"));
    }
}

class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<Character>();
        //特殊判断，如果为空就退出
        if(s.length()<=0&&(s.charAt(0)!='['||s.charAt(0)!='('||s.charAt(0)!='{')){
            return false;
        }
        char[] characters=s.toCharArray();

        for(char c:characters){
            if(c=='['||c=='{'||c=='('){
                stack.push(c);
            }
            else {
                Character c1 = stack.pop();
                if(c1=='['&&c==']'||c1=='{'&&c=='}'||c1=='('&&c==')'){
                    return true;
                }
            }
        }
        return false;

    }
}
